﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using QualityRpt.Utils;
using QualityRpt.Service;
using System.Data;
using System.Text;
using System.Collections;

namespace QualityRPT
{
    public partial class OBUUnRead : System.Web.UI.Page
    {
        int Suppliername = DeviceService.OBU_DEV;//标识  1  标签厂商
        public string PagerHtml = string.Empty;
        public string PagerHtml2 = string.Empty;
        public string strpage = string.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
            DateTime trackStart = DateTime.Now;
            this.obu_table_div.Attributes["style"] = "display:none;";//默认标签范围表格不显示
            if (!IsPostBack)
            {
                this.h_dev.Value = Suppliername.ToString();
                DataTable sptable = DeviceSupplierService.GetListSupplierName(string.Empty, string.Empty, Suppliername);
                this.ajax_spin.DataSource = sptable;
                this.ajax_spin.DataTextField = "SUPPLIER_NAME"; this.ajax_spin.DataValueField = "ID";
                this.ajax_spin.DataBind();

				DataTable initscTable =  DeviceSpecService.GetBySpIn(string.Empty, Suppliername);
				this.ajax_scin.DataSource = initscTable;
				this.ajax_scin.DataTextField = "SPEC_NAME"; this.ajax_scin.DataValueField = "ID";
				this.ajax_scin.DataBind ();

				DataTable cntable = DeviceContractDetailService.GetBySpecIn(string.Empty, Suppliername,null);
				this.ajax_cnin.DataSource = cntable;
				this.ajax_cnin.DataTextField = "CONTRACT_NO"; this.ajax_cnin.DataValueField = "CONTRACT_NO";
				this.ajax_cnin.DataBind();

                DataTable rdtable = NetWorkPlazaService.GetRoadList();//获得所有路段
                this.ajax_rdin.DataSource = rdtable;
                this.ajax_rdin.DataTextField = "ORGAN_NAME"; this.ajax_rdin.DataValueField = "ORGAN_ID";
                this.ajax_rdin.DataBind();

				DataTable plTable = NetWorkPlazaService.GetListByRdIn(string.Empty);//默认获得所有广场
				this.ajax_plazain.DataSource = plTable;
				this.ajax_plazain.DataTextField = "ORGAN_NAME"; this.ajax_plazain.DataValueField = "ORGAN_ID";
				this.ajax_plazain.DataBind ();

                DataTable lanetable = AirwirePlazaService.GetAllLane();//获得所有车道
                this.ajax_lanein.DataSource = lanetable;
                this.ajax_lanein.DataTextField = "LANE_NO"; this.ajax_lanein.DataValueField = "LANE_NO";
                this.ajax_lanein.DataBind();
                GetParams();
                if (strpage != string.Empty)
                {
                    BindData();
                }
                else
                {
                    this.textBoxStart.Text = DateTime.Now.ToString("yyyy-MM-dd 00:00");
                    this.textBoxEnd.Text = DateTime.Now.ToString("yyyy-MM-dd 23:59");
                }
            }
        }
        DateTime startTime; DateTime endTime; int statTType = 0; string strSpIn;
        string strSpecIn; string strCnIn; string strRdIn; string strPlazaIn; string strLaneIn;
        bool fromTemp;
        public DataTable obu_range_table = null;
        string[] obustartArray = null; string[] obuendArray = null;
        //string
        string strStartTime; string strEndTime; string strStatTType; string strFromTemp;
        string strobustart; string strobuend;
        /// <summary>
        /// 从url中获取
        /// </summary>
        private void GetParams()
        {
            strpage = Request.Params["p"];
            if (strpage == null)
            {
                strpage = string.Empty;
            }
            strSpIn = Request.Params["spin"];
            strSpecIn = Request.Params["scin"];
            strCnIn = Request.Params["cnin"];
            strRdIn = Request.Params["rdin"];
            strPlazaIn = Request.Params["plin"];
            strLaneIn = Request.Params["lnin"];
            strobustart = Request.Params["n1"];
            strobuend = Request.Params["n2"];
            strStartTime = Request.Params["t1"];
            strEndTime = Request.Params["t2"];
            strStatTType = Request.Params["tt"];
            strFromTemp = Request.Params["tp"];
        }
        /// <summary>
        /// 从form中获取
        /// </summary>
        private void PostParams()
        {
            strpage = string.Empty;
            strSpIn = Request.Params["ajax_spin"];
            strSpecIn = Request.Params["ajax_scin"];
            strCnIn = Request.Params["ajax_cnin"];
            strRdIn = Request.Params["ajax_rdin"];
            strPlazaIn = Request.Params["ajax_plazain"];
            strLaneIn = Request.Params["ajax_lanein"];
            strobustart = Request.Params["obustart"];
            strobuend = Request.Params["obuend"];
            strStartTime = Request.Params["textBoxStart"];
            strEndTime = Request.Params["textBoxEnd"];
            strStatTType = Request.Params["sel_statTType"];
            strFromTemp = Request.Params["cb_fromTemp"];
        }
        private void BindParams()
        {
            if (strpage == string.Empty)
            {
                strpage = "1";
            }
            #region 设置选中状态
            //厂商选中状态
            if (strSpIn != null && strSpIn.Trim() != string.Empty)
            {
                string[] selSpin = strSpIn.Split(new char[] { ',' });
                Hashtable hashSelSp = new Hashtable();
                for (int i = 0; i < selSpin.Length; i++)
                {
                    if (!hashSelSp.ContainsKey(selSpin[i]))
                    {
                        hashSelSp.Add(selSpin[i], 0);
                    }
                }
                for (int i = 0; i < ajax_spin.Items.Count; i++)
                {
                    if (hashSelSp.ContainsKey(ajax_spin.Items[i].Value))
                    {
                        ajax_spin.Items[i].Selected = true;
                    }
                }
            }
            //路段选中状态
            if (strRdIn != null && strRdIn.Trim() != string.Empty)
            {
                string[] selRdin = strRdIn.Split(new char[] { ',' });
                Hashtable hashSelRd = new Hashtable();
                for (int i = 0; i < selRdin.Length; i++)
                {
                    if (!hashSelRd.ContainsKey(selRdin[i]))
                    {
                        hashSelRd.Add(selRdin[i], 0);
                    }
                }
                for (int i = 0; i < ajax_rdin.Items.Count; i++)
                {
                    if (hashSelRd.ContainsKey(ajax_rdin.Items[i].Value))
                    {
                        ajax_rdin.Items[i].Selected = true;
                    }
                }
            }
            //车道状态
            if (strLaneIn != null && strLaneIn.Trim() != string.Empty)
            {
                string[] selLanein = strLaneIn.Split(new char[] { ',' });
                Hashtable hashSelLane = new Hashtable();
                for (int i = 0; i < selLanein.Length; i++)
                {
                    if (!hashSelLane.ContainsKey(selLanein[i]))
                    {
                        hashSelLane.Add(selLanein[i], 0);
                    }
                }
                for (int i = 0; i < ajax_lanein.Items.Count; i++)
                {
                    if (hashSelLane.ContainsKey(ajax_lanein.Items[i].Value))
                    {
                        ajax_lanein.Items[i].Selected = true;
                    }
                }
            }
            //型号选中状态
            if (strSpIn == null) { strSpIn = string.Empty; }
            DataTable sctable = DeviceSpecService.GetBySpIn(strSpIn, Suppliername);
            this.ajax_scin.DataSource = sctable;
            this.ajax_scin.DataTextField = "SPEC_NAME"; this.ajax_scin.DataValueField = "ID";
            this.ajax_scin.DataBind();
            if (strSpecIn != null && strSpecIn.Trim() != string.Empty)
            {
                string[] selScin = strSpecIn.Split(new char[] { ',' });
                Hashtable hashSelSc = new Hashtable();
                for (int i = 0; i < selScin.Length; i++)
                {
                    if (!hashSelSc.ContainsKey(selScin[i]))
                    {
                        hashSelSc.Add(selScin[i], 0);
                    }
                }
                for (int i = 0; i < ajax_scin.Items.Count; i++)
                {
                    if (hashSelSc.ContainsKey(ajax_scin.Items[i].Value))
                    {
                        ajax_scin.Items[i].Selected = true;
                    }
                }
            }
            //合同选中状态
            if (strSpecIn != null && strSpecIn.Trim() != string.Empty)
            {
                DataTable cntable = DeviceContractDetailService.GetBySpecIn(strSpecIn, Suppliername,null);
                this.ajax_cnin.DataSource = cntable;
                this.ajax_cnin.DataTextField = "CONTRACT_NO"; this.ajax_cnin.DataValueField = "CONTRACT_NO";
                this.ajax_cnin.DataBind();
                if (strCnIn != null && strCnIn.Trim() != string.Empty)
                {
                    string[] selCnin = strCnIn.Split(new char[] { ',' });
                    Hashtable hashSelCn = new Hashtable();
                    for (int i = 0; i < selCnin.Length; i++)
                    {
                        if (!hashSelCn.ContainsKey(selCnin[i]))
                        {
                            hashSelCn.Add(selCnin[i], 0);
                        }
                    }
                    for (int i = 0; i < ajax_cnin.Items.Count; i++)
                    {
                        if (hashSelCn.ContainsKey(ajax_cnin.Items[i].Value))
                        {
                            ajax_cnin.Items[i].Selected = true;
                        }
                    }
                }
            }
            //广场选中状态
            if (strRdIn == null) { strRdIn = string.Empty; }
            DataTable plazatable = NetWorkPlazaService.GetListByRdIn(strRdIn);
            this.ajax_plazain.DataSource = plazatable;
            this.ajax_plazain.DataTextField = "ORGAN_NAME"; this.ajax_plazain.DataValueField = "ORGAN_ID";
            this.ajax_plazain.DataBind();
            if (strPlazaIn != null && strPlazaIn.Trim() != string.Empty)
            {
                string[] selPlazain = strPlazaIn.Split(new char[] { ',' });
                Hashtable hashSelPlaza = new Hashtable();
                for (int i = 0; i < selPlazain.Length; i++)
                {
                    if (!hashSelPlaza.ContainsKey(selPlazain[i]))
                    {
                        hashSelPlaza.Add(selPlazain[i], 0);
                    }
                }
                for (int i = 0; i < ajax_plazain.Items.Count; i++)
                {
                    if (hashSelPlaza.ContainsKey(ajax_plazain.Items[i].Value))
                    {
                        ajax_plazain.Items[i].Selected = true;
                    }
                }
            }
            #endregion
            //标签范围
            if (strobustart != null && strobustart.Trim() != string.Empty
                && strobuend != null && strobuend.Trim() != string.Empty)
            {
                obustartArray = strobustart.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                obuendArray = strobuend.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                if (obustartArray.Length > 0 && obuendArray.Length > 0)
                {
                    obu_range_table = new DataTable();
                    obu_range_table.Columns.Add("obustart"); obu_range_table.Columns.Add("obuend");
                    for (int i = 0; i < obustartArray.Length; i++)
                    {
                        DataRow crow = obu_range_table.NewRow();
                        crow["obustart"] = obustartArray[i];
                        crow["obuend"] = obuendArray[i];
                        obu_range_table.Rows.Add(crow);
                    }
                    this.obu_table_div.Attributes["style"] = "display:block;";
                    this.repeater_obu_range.DataSource = obu_range_table;
                    this.repeater_obu_range.DataBind();
                }
            }
            if (strStartTime != null && strStartTime != string.Empty)
            {
                textBoxStart.Text = strStartTime;
                startTime = DateTime.Parse(strStartTime);
            }
            if (strEndTime != null && strEndTime != string.Empty)
            {
                textBoxEnd.Text = strEndTime;
                endTime = DateTime.Parse(strEndTime).AddSeconds(59);
            }
            if (strStatTType != null && strStatTType.Trim() != string.Empty)
            {
                sel_statTType.Value = strStatTType;
                statTType = int.Parse(strStatTType);
            }
            fromTemp = strFromTemp == "1" ? true : false;
            cb_fromTemp.Checked = fromTemp;
        }
        private void BindData()
        {
            BindParams();
            DateTime trackStart = DateTime.Now;
            StringBuilder sbGroupTitle = new StringBuilder();
            StringBuilder sbGroupName = new StringBuilder();
            StringBuilder sbCondition = new StringBuilder();
            StringBuilder sbGroupNameTitle = new StringBuilder();
            bool nogroup = true;
            if (strSpIn != null && strSpIn.Trim() != string.Empty)
            {
                sbGroupTitle.Append("厂商,"); sbGroupNameTitle.Append("SUPPLIER_NAME,");
                sbGroupName.Append("D.SUPPLIER_NAME,"); nogroup = false;
                sbCondition.Append(" AND D.SUPPLIER_ID IN (" + strSpIn + ")");
            }
            if (strSpecIn != null && strSpecIn.Trim() != string.Empty)
            {
                sbGroupTitle.Append("型号,"); sbGroupNameTitle.Append("SPEC_NAME,");
                sbGroupName.Append("D.SPEC_NAME,"); nogroup = false;
                sbCondition.Append(" AND D.SPEC_ID IN (" + strSpecIn + ")");
            }
            if (strCnIn != null && strCnIn.Trim() != string.Empty)
            {
                sbGroupTitle.Append("合同,"); sbGroupNameTitle.Append("CONTRACT_NO,");
                sbGroupName.Append("D.CONTRACT_NO,"); nogroup = false;
                sbCondition.Append(" AND D.CONTRACT_NO IN(" + StringUtils.FormatStrInSql(strCnIn) + ")");
            }
			if ((obustartArray != null && obustartArray.Length > 0) || fromTemp) {
				sbGroupTitle.Append("标签号,"); sbGroupNameTitle.Append("OBUNO,");
				nogroup = false;
			}
			if (nogroup)
			{
				sbGroupTitle.Append("厂商,型号,"); sbGroupNameTitle.Append("SUPPLIER_NAME,SPEC_NAME,");
				sbGroupName.Append("D.SUPPLIER_NAME,D.SPEC_NAME,");
			}
            switch (statTType)
            {
                case 1:
                    sbGroupTitle.Append("年,月,"); sbGroupNameTitle.Append("STYEAR,STMONTH,");
                    break;
                case 2:
                    sbGroupTitle.Append("年,周,"); sbGroupNameTitle.Append("STYEAR,STWEEK,");
                    break;
                case 3:
                    sbGroupTitle.Append("年,月,日,"); sbGroupNameTitle.Append("STYEAR,STMONTH,STDAY,");
                    break;
                case 4:
                    sbGroupTitle.Append("年,月,日,时,"); sbGroupNameTitle.Append("STYEAR,STMONTH,STDAY,STHOUR,");
                    break;
            }
            
            if (strRdIn != null && strRdIn.Trim() != string.Empty)
            {
                sbCondition.Append(" AND A.ROAD_ID IN (" + strRdIn + ")");
            }
            if (strPlazaIn != null && strPlazaIn.Trim() != string.Empty)
            {
                sbCondition.Append(" AND A.PLAZA_ID IN (" + strPlazaIn + ")");
            }
            if (strLaneIn != null && strLaneIn.Trim() != string.Empty)
            {
                sbCondition.Append(" AND A.LANE_NO IN (" + strLaneIn + ")");
            }
            AutoColumns = sbGroupNameTitle.ToString().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            AutoColumnTitles = sbGroupTitle.ToString().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            this.repeater_title.DataSource = AutoColumnTitles; this.repeater_title.DataBind();
            //获取统计指标
            string statIndic = "TRANSCOUNT,TRANSDCOUNT,UNREAD_TRANSCOUNT,UNREAD_RATE";
            statTable = TransNoteService.GetOBUStatByQ(startTime, endTime, statIndic, statTType, strSpIn, strSpecIn, strCnIn, strRdIn, strPlazaIn, strLaneIn, true, fromTemp, obustartArray, obuendArray);
            this.repeater_data.DataSource = statTable; this.repeater_data.DataBind();
            //获取交易明细
            PageUtils pu = new PageUtils(); pu.Page = Convert.ToInt32(strpage); pu.PerPageNum = 50;
            detailTable = UNReadTransService.GetOBUDetailByQ(startTime, endTime, strSpIn, strSpecIn, strCnIn, strRdIn, strPlazaIn, strLaneIn, fromTemp, obustartArray, obuendArray, pu);
            this.repeater_Detail.DataSource = detailTable;
            this.repeater_Detail.DataBind();
            string pagerparams = "/OBUUnread.aspx?pid=" + Request.Params["pid"] + "&cid=" + Request.Params["cid"] + "&p={page}&t1=" + strStartTime + "&t2=" + strEndTime
               + "&spin=" + strSpIn + "&scin=" + strSpecIn + "&cnin=" + strCnIn + "&rdin=" + strRdIn + "&plin=" + strPlazaIn + "&lnin=" + strLaneIn
               + "&n1=" + strobustart + "&n2=" + strobuend + "&tt=" + strStatTType + "&tp=" + strFromTemp;
            PagerHtml = pu.GenStPagination(pagerparams + "&tab=tabDetail");
            //获取交易标签
            obudetailTable = UNReadTransService.GetOBUGDetailByQ(startTime, endTime, strSpIn, strSpecIn, strCnIn, strRdIn, strPlazaIn, strLaneIn, fromTemp, obustartArray, obuendArray, pu);
            this.repeater_dataobu.DataSource = obudetailTable;
            this.repeater_dataobu.DataBind();
            PagerHtml2 = pu.GenStPagination(pagerparams + "&tab=tabOBU");
            TimeSpan ts_consume = DateTime.Now - trackStart;
            this.span_t_consume.InnerText = "查询统计耗时:" + ts_consume.TotalSeconds + "s";
        }
        //
        DataTable statTable = null;
        DataTable detailTable = null;
        DataTable obudetailTable = null;
        DataTable obudetailTableNoPage = null;
        string[] AutoColumns = null;
        string[] AutoColumnTitles = null;
        /// <summary>
        /// 根据列名生成需要显示的分组列
        /// </summary>
        /// <param name="rIndex"></param>
        /// <returns></returns>
        public string GetAutoColumns(object rIndex)
        {
            StringBuilder sbText = new StringBuilder();
            if (AutoColumns != null && statTable != null)
            {
                for (int i = 0; i < AutoColumns.Length; i++)
                {
                    sbText.Append("<td>" + statTable.Rows[Convert.ToInt32(rIndex)][AutoColumns[i]] + "</td>");
                }
            }
            return sbText.ToString();
        }
        protected void ButtonQ_Click(object sender, EventArgs e)
        {
            PostParams();
            BindData();
        }
        //导出统计结果数据
        protected void ButtonExport_Click(object sender, EventArgs e)
        {
            if (statTable == null)
            {
                PostParams();
                BindData();
                string checkDate = DateTime.Parse(textBoxStart.Text).ToString("yyyy年MM月dd日") + "-" + DateTime.Parse(textBoxEnd.Text).ToString("yyyy年MM月dd日");
                string reportFile = Server.MapPath("/ReportTemplate/电子标签漏读统计报表.xls");
                SpreadsheetGear.IWorkbook workbook = SpreadsheetGear.Factory.GetWorkbook(reportFile);
                if (statTable == null || statTable.Rows.Count == 0)
                {
                    Common.Utility.Alert("您查询的内容不存在！", this.Page);
                    return;
                }
                //设置虚拟数据表newtab存放所要的数据列
                DataTable newtab = new DataTable();
                switch (statTType)
                {
                    case 1:
                        newtab.Columns.Add("年份");
                        newtab.Columns.Add("月份");
                        break;
                    case 2:
                        newtab.Columns.Add("年份");
                        newtab.Columns.Add("周");
                        break;
                    case 3:
                        newtab.Columns.Add("年份");
                        newtab.Columns.Add("月份");
                        newtab.Columns.Add("日");
                        break;
                    case 4:
                        newtab.Columns.Add("年份");
                        newtab.Columns.Add("月份");
                        newtab.Columns.Add("日");
                        newtab.Columns.Add("时");
                        break;
                }
                if (strSpIn != null && strSpIn.Trim() != string.Empty)
                {
                    newtab.Columns.Add("厂商名称");
                }
                if (strSpecIn != null && strSpecIn.Trim() != string.Empty)
                {
                    newtab.Columns.Add("型号名称");
                }
                if (strCnIn != null && strCnIn.Trim() != string.Empty)
                {
                    newtab.Columns.Add("合同号");
                }
                if ((strSpIn == null || strSpIn.Trim() == string.Empty) && (strSpecIn == null || strSpecIn.Trim() == string.Empty) && (strCnIn == null || strCnIn.Trim() == string.Empty))
                {
					if (obustartArray == null || obustartArray.Length < 1) {
						newtab.Columns.Add ("厂商名称");
						newtab.Columns.Add ("型号名称");
					}
                }
                newtab.Columns.Add("漏读交易个数");
                newtab.Columns.Add("标签交易量");
                newtab.Columns.Add("漏读交易比例");

                //遍历源数据表对新数据表各行进行赋值
                for (int i = 0; i < statTable.Rows.Count; i++)
                {
                    DataRow newRow = newtab.NewRow();
                    switch (statTType)
                    {
                        case 1:
                            newRow["年份"] = statTable.Rows[i]["STYEAR"];
                            newRow["月份"] = statTable.Rows[i]["STMONTH"];
                            break;
                        case 2:
                            newRow["年份"] = statTable.Rows[i]["STYEAR"];
                            newRow["周"] = statTable.Rows[i]["STWEEK"];
                            break;
                        case 3:
                            newRow["年份"] = statTable.Rows[i]["STYEAR"];
                            newRow["月份"] = statTable.Rows[i]["STMONTH"];
                            newRow["日"] = statTable.Rows[i]["STDAY"];
                            break;
                        case 4:
                            newRow["年份"] = statTable.Rows[i]["STYEAR"];
                            newRow["月份"] = statTable.Rows[i]["STMONTH"];
                            newRow["日"] = statTable.Rows[i]["STDAY"];
                            newRow["时"] = statTable.Rows[i]["STHOUR"];
                            break;
                    }
                    if (strSpIn != null && strSpIn.Trim() != string.Empty)
                    {
                        newRow["厂商名称"] = statTable.Rows[i]["SUPPLIER_NAME"];
                    }
                    if (strSpecIn != null && strSpecIn.Trim() != string.Empty)
                    {
                        newRow["型号名称"] = statTable.Rows[i]["SPEC_NAME"];
                    }
                    if (strCnIn != null && strCnIn.Trim() != string.Empty)
                    {
                        newRow["合同号"] = statTable.Rows[i]["CONTRACT_NO"];
                    }
                    if ((strSpIn == null || strSpIn.Trim() == string.Empty) && (strSpecIn == null || strSpecIn.Trim() == string.Empty) && (strCnIn == null || strCnIn.Trim() == string.Empty))
                    {
						if (obustartArray == null || obustartArray.Length < 1) {
							newRow ["厂商名称"] = statTable.Rows [i] ["SUPPLIER_NAME"];
							newRow ["型号名称"] = statTable.Rows [i] ["SPEC_NAME"];
						}
                    }
                    newRow["漏读交易个数"] = statTable.Rows[i]["UNREAD_TRANSCOUNT"];
                    newRow["标签交易量"] = statTable.Rows[i]["TRANSCOUNT"];
                    newRow["漏读交易比例"] = statTable.Rows[i]["UNREAD_RATE"];
                    newtab.Rows.Add(newRow);
                }
                #region 拼表格名称
                string b = ""; string c = ""; string d = ""; string f = "";

                switch (statTType)
                {
                    case 0://无分组                        
                        b = "无分组";
                        break;
                    case 1://按月                      
                        b = "按月";
                        break;
                    case 2://按周                        
                        b = "按周";
                        break;
                    case 3://按日                        
                        b = "按日";
                        break;
                    case 4://按时                       
                        b = "按时";
                        break;
                }
                if (strSpIn != null && strSpIn.Trim() != string.Empty)
                {
                    c = "厂商";
                }
                if (strSpecIn != null && strSpecIn.Trim() != string.Empty)
                {
                    d = "型号";
                }
                if (strCnIn != null && strCnIn.Trim() != string.Empty)
                {
                    f = "合同";
                }

                #endregion
                string file_name = "电子标签漏读统计" + b + c + d + f + "报表" + "(" + DateTime.Parse(textBoxStart.Text).ToString("yyyy-MM-dd_HH：mm：ss") + "-" + DateTime.Parse(textBoxEnd.Text).ToString("yyyy-MM-dd_HH：mm：ss") + ")" + ".xls";
                switch (statTType)
                {
                    case 0://无分组
                        {
                            #region 厂商、型号、合同号排列组合的八种
                            if ((strSpIn != null && strSpIn.Trim() != string.Empty) && strSpecIn != null && strCnIn != null)//厂商、型号、合同号都不为空
                            {
                                string[] aa = new string[] { "G" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn != null && strSpIn.Trim() != string.Empty) && strSpecIn != null && strCnIn == null)//厂商不为空、型号不为空、合同号为空
                            {
                                string[] aa = new string[] { "F" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);

                            }
                            if ((strSpIn != null && strSpIn.Trim() != string.Empty) && strSpecIn == null && strCnIn != null)//厂商不为空、型号为空、合同号不为空
                            {
                                string[] aa = new string[] { "F" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn != null && strSpIn.Trim() != string.Empty) && strSpecIn == null && strCnIn == null)//厂商不为空、型号为空、合同号为空
                            {
                                string[] aa = new string[] { "E" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn == null || strSpIn.Trim() == string.Empty) && strSpecIn == null && strCnIn == null)//厂商为空、型号为空、合同号为空
                            {
                                string[] aa = new string[] { "F" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn == null || strSpIn.Trim() == string.Empty) && strSpecIn == null && strCnIn != null)//厂商为空、型号为空、合同号不为空
                            {
                                string[] aa = new string[] { "E" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn == null || strSpIn.Trim() == string.Empty) && strSpecIn != null && strCnIn == null)//厂商为空、型号不为空、合同号为空
                            {
                                string[] aa = new string[] { "E" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn == null || strSpIn.Trim() == string.Empty) && strSpecIn != null && strCnIn != null)//厂商为空、型号不为空、合同号不为空
                            {
                                string[] aa = new string[] { "F" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            break;
                            #endregion
                        }
                    case 1://按月
                        {
                            #region 厂商、型号、合同号排列组合的八种
                            if ((strSpIn != null && strSpIn.Trim() != string.Empty) && strSpecIn != null && strCnIn != null)//厂商、型号、合同号都不为空
                            {
                                string[] aa = new string[] { "I" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn != null && strSpIn.Trim() != string.Empty) && strSpecIn != null && strCnIn == null)//厂商不为空、型号不为空、合同号为空
                            {
                                string[] aa = new string[] { "H" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn != null && strSpIn.Trim() != string.Empty) && strSpecIn == null && strCnIn != null)//厂商不为空、型号为空、合同号不为空
                            {
                                string[] aa = new string[] { "H" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn != null && strSpIn.Trim() != string.Empty) && strSpecIn == null && strCnIn == null)//厂商不为空、型号为空、合同号为空
                            {
                                string[] aa = new string[] { "G" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn == null || strSpIn.Trim() == string.Empty) && strSpecIn == null && strCnIn == null)//厂商为空、型号为空、合同号为空
                            {
                                string[] aa = new string[] { "H" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn == null || strSpIn.Trim() == string.Empty) && strSpecIn == null && strCnIn != null)//厂商为空、型号为空、合同号不为空
                            {
                                string[] aa = new string[] { "G" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn == null || strSpIn.Trim() == string.Empty) && strSpecIn != null && strCnIn == null)//厂商为空、型号不为空、合同号为空
                            {
                                string[] aa = new string[] { "G" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn == null || strSpIn.Trim() == string.Empty) && strSpecIn != null && strCnIn != null)//厂商为空、型号不为空、合同号不为空
                            {
                                string[] aa = new string[] { "H" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            break;
                            #endregion
                        }
                    case 2://按周
                        {
                            #region 厂商、型号、合同号排列组合的八种
                            if ((strSpIn != null && strSpIn.Trim() != string.Empty) && strSpecIn != null && strCnIn != null)//厂商、型号、合同号都不为空
                            {
                                string[] aa = new string[] { "I" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn != null && strSpIn.Trim() != string.Empty) && strSpecIn != null && strCnIn == null)//厂商不为空、型号不为空、合同号为空
                            {
                                string[] aa = new string[] { "H" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn != null && strSpIn.Trim() != string.Empty) && strSpecIn == null && strCnIn != null)//厂商不为空、型号为空、合同号不为空
                            {
                                string[] aa = new string[] { "H" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn != null && strSpIn.Trim() != string.Empty) && strSpecIn == null && strCnIn == null)//厂商不为空、型号为空、合同号为空
                            {
                                string[] aa = new string[] { "G" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn == null || strSpIn.Trim() == string.Empty) && strSpecIn == null && strCnIn == null)//厂商为空、型号为空、合同号为空
                            {
                                string[] aa = new string[] { "H" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn == null || strSpIn.Trim() == string.Empty) && strSpecIn == null && strCnIn != null)//厂商为空、型号为空、合同号不为空
                            {
                                string[] aa = new string[] { "G" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn == null || strSpIn.Trim() == string.Empty) && strSpecIn != null && strCnIn == null)//厂商为空、型号不为空、合同号为空
                            {
                                string[] aa = new string[] { "G" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn == null || strSpIn.Trim() == string.Empty) && strSpecIn != null && strCnIn != null)//厂商为空、型号不为空、合同号不为空
                            {
                                string[] aa = new string[] { "H" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            break;
                            #endregion
                        }
                    case 3://按日
                        {
                            #region 厂商、型号、合同号排列组合的八种
                            if ((strSpIn != null && strSpIn.Trim() != string.Empty) && strSpecIn != null && strCnIn != null)//厂商、型号、合同号都不为空
                            {
                                string[] aa = new string[] { "J" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn != null && strSpIn.Trim() != string.Empty) && strSpecIn != null && strCnIn == null)//厂商不为空、型号不为空、合同号为空
                            {
                                string[] aa = new string[] { "I" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn != null && strSpIn.Trim() != string.Empty) && strSpecIn == null && strCnIn != null)//厂商不为空、型号为空、合同号不为空
                            {
                                string[] aa = new string[] { "I" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn != null && strSpIn.Trim() != string.Empty) && strSpecIn == null && strCnIn == null)//厂商不为空、型号为空、合同号为空
                            {
                                string[] aa = new string[] { "H" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn == null || strSpIn.Trim() == string.Empty) && strSpecIn == null && strCnIn == null)//厂商为空、型号为空、合同号为空
                            {
                                string[] aa = new string[] { "I" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn == null || strSpIn.Trim() == string.Empty) && strSpecIn == null && strCnIn != null)//厂商为空、型号为空、合同号不为空
                            {
                                string[] aa = new string[] { "H" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn == null || strSpIn.Trim() == string.Empty) && strSpecIn != null && strCnIn == null)//厂商为空、型号不为空、合同号为空
                            {
                                string[] aa = new string[] { "H" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn == null || strSpIn.Trim() == string.Empty) && strSpecIn != null && strCnIn != null)//厂商为空、型号不为空、合同号不为空
                            {
                                string[] aa = new string[] { "I" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            break;
                            #endregion
                        }
                    case 4://按时
                        {
                            #region 厂商、型号、合同号排列组合的八种
                            if ((strSpIn != null && strSpIn.Trim() != string.Empty) && strSpecIn != null && strCnIn != null)//厂商、型号、合同号都不为空
                            {
                                string[] aa = new string[] { "K" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn != null && strSpIn.Trim() != string.Empty) && strSpecIn != null && strCnIn == null)//厂商不为空、型号不为空、合同号为空
                            {
                                string[] aa = new string[] { "J" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn != null && strSpIn.Trim() != string.Empty) && strSpecIn == null && strCnIn != null)//厂商不为空、型号为空、合同号不为空
                            {
                                string[] aa = new string[] { "J" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn != null && strSpIn.Trim() != string.Empty) && strSpecIn == null && strCnIn == null)//厂商不为空、型号为空、合同号为空
                            {
                                string[] aa = new string[] { "I" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn == null || strSpIn.Trim() == string.Empty) && strSpecIn == null && strCnIn == null)//厂商为空、型号为空、合同号为空
                            {
                                string[] aa = new string[] { "J" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn == null || strSpIn.Trim() == string.Empty) && strSpecIn == null && strCnIn != null)//厂商为空、型号为空、合同号不为空
                            {
                                string[] aa = new string[] { "I" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn == null || strSpIn.Trim() == string.Empty) && strSpecIn != null && strCnIn == null)//厂商为空、型号不为空、合同号为空
                            {
                                string[] aa = new string[] { "I" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn == null || strSpIn.Trim() == string.Empty) && strSpecIn != null && strCnIn != null)//厂商为空、型号不为空、合同号不为空
                            {
                                string[] aa = new string[] { "J" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            break;
                            #endregion
                        }
                }

            }
        }
        //导出标签明细数据
        protected void ButtonExportDetail_Click(object sender, EventArgs e)
        {
            if (obudetailTable == null)
            {
                PostParams();
                BindData();
                //获取全部交易标签（无分页）
                obudetailTableNoPage = UNReadTransService.GetOBUGDetailByQ(startTime, endTime, strSpIn, strSpecIn, strCnIn, strRdIn, strPlazaIn, strLaneIn, fromTemp, obustartArray, obuendArray, null);
                if (obudetailTable == null || obudetailTable.Rows.Count == 0)
                {
                    Common.Utility.Alert("您查询的内容不存在！", this.Page);
                    return;
                }
                DataTable newtab = new DataTable();
                newtab.Columns.Add("厂商名称");
                newtab.Columns.Add("标签型号");
                newtab.Columns.Add("标签号");
                newtab.Columns.Add("漏读交易次数");
                newtab.Columns.Add("标签交易量");
                newtab.Columns.Add("漏读交易比列");
                for (int i = 0; i < obudetailTable.Rows.Count; i++)
                {

                    DataRow newRow = newtab.NewRow();
                    newRow["厂商名称"] = obudetailTable.Rows[i]["SUPPLIER_NAME"];
                    newRow["标签型号"] = obudetailTable.Rows[i]["SPEC_NAME"];
                    newRow["标签号"] = obudetailTable.Rows[i]["OBUNO"];
                    newRow["漏读交易次数"] = obudetailTable.Rows[i]["UNREAD_TRANSCOUNT"];
                    newRow["标签交易量"] = obudetailTable.Rows[i]["SUM_TRANSCOUNT"];
                    newRow["漏读交易比列"] = obudetailTable.Rows[i]["UNREAD_RATE"];
                    newtab.Rows.Add(newRow);
                }
                string[] aa = new string[] { "G" };
                string file_name = "电子标签漏读信息报表" + "(" + DateTime.Parse(textBoxStart.Text).ToString("yyyy-MM-dd_HH：mm：ss") + "-" + DateTime.Parse(textBoxEnd.Text).ToString("yyyy-MM-dd_HH：mm：ss") + ")" + ".xls";
                string checkDate = DateTime.Parse(textBoxStart.Text).ToString("yyyy年MM月dd日") + "-" + DateTime.Parse(textBoxEnd.Text).ToString("yyyy年MM月dd日");
                string reportFile = Server.MapPath("/ReportTemplate/电子标签漏读信息报表.xls");
                SpreadsheetGear.IWorkbook workbook = SpreadsheetGear.Factory.GetWorkbook(reportFile);
                Common.Common.NOAutoExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);

            }
        }
    }
}